﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Productions;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Strippings
{
    public class StrippingStatusBackHandler : IRequestHandler<StrippingStatusBackCommand, ResultsDTO>
    {
        #region 仓储
        private readonly IBateRepository<Stripping> StrippingRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="StrippingRepository"></param>
        public StrippingStatusBackHandler(IBateRepository<Stripping> StrippingRepository)
        {
            this.StrippingRepository = StrippingRepository;
        }
        #endregion

        #region 退料审批
        /// <summary>
        /// 退料审批
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(StrippingStatusBackCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };

            //连接数据库
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesWrite;

            //实体
            var stripping = new Stripping();
            var str = "update productionwork set StrippingStatus='" + request.StrippingStatus + "' where StrippingId='" + request.StrippingId + "'";
            var result = StrippingRepository.Add(str, stripping, conn);
            if (result != null)
            {
                list.Code = 1;
                list.Message = "修改成功";
            }
            return list;
        }
        #endregion

    }
}